using System.Runtime.InteropServices;
using Eneta.Portal.Common;
using Eneta.Portal.Common.Definitions;
using Def = Eneta.Portal.Common.Definitions;
using Microsoft.SharePoint;

namespace Eneta.Portal.Deployment.Features.Eneta.Site.ContentTypes
{    
    [Guid("ae948c2d-886b-4f47-bd27-555db8f1f69c")]
    public class EnetaSiteEventReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var web = properties.Feature.Parent as SPWeb;
            if (web == null)
                web = ((SPSite)properties.Feature.Parent).RootWeb;

            //web.AddFieldToContentType("EnetaKeywords", "Raamat");
            //web.AddFieldToContentType("EnetaKeywords", "Ajakiri");

            var blogEntryCtId = new SPContentTypeId(Def.ContentTypes.BlogEntry);
            web.AddFieldToContentType(BlogEntryFields.Keywords, blogEntryCtId);

            var annId = new SPContentTypeId(Def.ContentTypes.Announcement);
            web.AddFieldToContentType(AnnouncementFields.Keywords, annId);

            var companyId = new SPContentTypeId(Def.ContentTypes.Company);
            web.AddFieldToContentType(CompanyFields.Offices, companyId);
        }

        public static void AddFields(SPWeb web)
        {
            var blogEntryCtId = new SPContentTypeId(Def.ContentTypes.BlogEntry);
            web.AddFieldToContentType(BlogEntryFields.Keywords, blogEntryCtId);

            var annId = new SPContentTypeId(Def.ContentTypes.Announcement);
            web.AddFieldToContentType(AnnouncementFields.Keywords, annId);
            var companyId = new SPContentTypeId(Def.ContentTypes.Company);
            web.AddFieldToContentType(CompanyFields.Offices, companyId);
        }
    }
}
